package m2_work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws Exception {
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");
        Connection con = f.newConnection();
        Channel c = con.createChannel();

        c.queueDeclare("helloworld",
                false,//是否是持久队列
                false,//排他队列，独占队列
                false,//自动删除
                null);//其他属性
        while (true){
            System.out.println("输入消息: ");
            String msg = new Scanner(System.in).nextLine();
            c.basicPublish("",
                            "helloworld",
                            null,
                    msg.getBytes());
            System.out.println("消息已发送");
        }
    }
}
